﻿using System;
using System.Windows.Automation;
using QuickUIT.Controls; 

namespace QuickUIT
{
    /// <summary>
    /// Provides functionality for geting a <see cref="UIBaseControl"/> based off a <see cref="ControlType"/>. 
    /// </summary>
    public static class ControlFactory
    {
        /// <summary>
        /// Gets a <see cref="UIBaseControl"/> type for a specified <see cref="ControlType"/>. 
        /// </summary>
        /// <param name="element">The underlying <see cref="AutomationElement"/> for the control.</param>
        /// <param name="controlType">The control type of the control.</param>
        /// <returns>A <see cref="UIBaseControl"/> type for the specified control type.</returns>
        public static UIBaseControl GetUIControl(AutomationElement element, ControlType controlType)
        {
            if (controlType == ControlType.Button)
                return new UIButton(element);
            if (controlType == ControlType.Calendar)
                return new UICalendar(element);
            if (controlType == ControlType.CheckBox)
                return new UICheckBox(element);
            if (controlType == ControlType.ComboBox)
                return new UIComboBox(element);
            if (controlType == ControlType.Custom)
                return new UICustom(element);
            if (controlType == ControlType.DataGrid)
                return new UIDataGrid(element);
            if (controlType == ControlType.DataItem)
                return new UIDataItem(element);
            if (controlType == ControlType.Document)
                return new UIDocument(element);
            if (controlType == ControlType.Edit)
                return new UIEdit(element);
            if (controlType == ControlType.Group)
                return new UIGroup(element);
            if (controlType == ControlType.Header)
                return new UIHeader(element);
            if (controlType == ControlType.HeaderItem)
                return new UIHeaderItem(element);
            if (controlType == ControlType.Hyperlink)
                return new UIHyperlink(element);
            if (controlType == ControlType.Image)
                return new UIImage(element);
            if (controlType == ControlType.List)
                return new UIList(element);
            if (controlType == ControlType.ListItem)
                return new UIListItem(element);
            if (controlType == ControlType.Menu)
                return new UIMenu(element);
            if (controlType == ControlType.MenuBar)
                return new UIMenuBar(element);
            if (controlType == ControlType.MenuItem)
                return new UIMenuItem(element);
            if (controlType == ControlType.Pane)
                return new UIPane(element);
            if (controlType == ControlType.ProgressBar)
                return new UIProgressBar(element);
            if (controlType == ControlType.RadioButton)
                return new UIRadioButton(element);
            if (controlType == ControlType.ScrollBar)
                return new UIScrollBar(element);
            if (controlType == ControlType.Separator)
                return new UISeparator(element);
            if (controlType == ControlType.Slider)
                return new UISlider(element);
            if (controlType == ControlType.Spinner)
                return new UISpinner(element);
            if (controlType == ControlType.SplitButton)
                return new UISplitButton(element);
            if (controlType == ControlType.StatusBar)
                return new UIStatusBar(element);
            if (controlType == ControlType.Tab)
                return new UITab(element);
            if (controlType == ControlType.TabItem)
                return new UITabItem(element);
            if (controlType == ControlType.Table)
                return new UITable(element);
            if (controlType == ControlType.Text)
                return new UIText(element);
            if (controlType == ControlType.Thumb)
                return new UIThumb(element);
            if (controlType == ControlType.TitleBar)
                return new UITitleBar(element);
            if (controlType == ControlType.ToolBar)
                return new UIToolBar(element);
            if (controlType == ControlType.ToolTip)
                return new UIToolTip(element);
            if (controlType == ControlType.Tree)
                return new UITree(element);
            if (controlType == ControlType.TreeItem)
                return new UITreeItem(element);
            if (controlType == ControlType.Window)
                return new UIWindow(element); 

            throw new InvalidOperationException(String.Format("The control type '{0}' is not recognized.", controlType.ProgrammaticName));
        }
    }
}
